import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-03-29
 * Time: 18:53
 */
class NameException extends Exception{
    public NameException(String message) {
        super(message);
    }
}
class PasswordException extends Exception{
    public PasswordException(String message) {
        super(message);
    }
}
class Login {
    private String name = "amy";
    private String password = "12345";

    public void loginInfo(String uname, String upassword) throws NameException, PasswordException {
        if (!name.equals(uname)) {
            throw new NameException("用户名错误");
        }
        if (!password.equals(upassword)) {
            throw new PasswordException("密码错误");
        }
        System.out.println("登陆成功！");
    }
}
class Person implements Cloneable{
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Test {
    public static void main(String[] args) {
        Login login = new Login();
        System.out.println("请输入用户名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        try {
            login.loginInfo(name,password);
        } catch (NameException | PasswordException e) {
            e.printStackTrace();
        } finally {
            scanner.close();
        }

    }
    public static void main1(String[] args) {
        Person person = new Person();

        try (Scanner scanner = new Scanner(System.in)) {//不可能同时捕获多个异常
            //int[] arr = null;
            int a = scanner.nextInt();
            //System.out.println(arr.length);
            //Person person1 = (Person) person.clone();
            System.out.println(10 / a);
//        } catch (ArithmeticException e) {
//            e.printStackTrace();
//            //throw new RuntimeException(e);
//            System.out.println("我捕获到了这个异常");
//        } catch (NullPointerException e) {
//            e.printStackTrace();
//            System.out.println("我捕获了空指针异常");
        } catch (Exception e) {//兜底
            e.printStackTrace();
            System.out.println("我捕获到了异常");
        } finally {
            System.out.println("finally");
        }
        System.out.println("after");
    }
}
